package cc.laop.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.io.Serializable;

/**
 * Created by Pengpeng on 2017/5/27.
 */
@Service
public class RedisService {

    private static final Logger logger = LoggerFactory.getLogger(RedisService.class);

    @Autowired
    private RedisTemplate<Serializable, Object> redisTemplate;

    public HashOperations<Serializable, Serializable, Object> hash() {
        return redisTemplate.opsForHash();
    }

    public ListOperations<Serializable, Object> list() {
        return redisTemplate.opsForList();
    }


    public RedisTemplate<Serializable, Object> getRedisTemplate() {
        return redisTemplate;
    }

    public void hashPut(Serializable key, Serializable hashkey, Object object) {
        HashOperations<Serializable, Serializable, Object> hashops = redisTemplate.opsForHash();
        hashops.put(key, hashkey, object);
    }

    public Object hashGet(Serializable key, Serializable hashkey) {
        HashOperations<Serializable, Serializable, Object> hashops = redisTemplate.opsForHash();
        return hashops.get(key, hashkey);
    }

}
